function ShowStockList(g_var) {	
	
	var stkOpt = "";
	//for (var j in g_var.stkDiv) {
	for (var j=0; j < g_var.stkGroup.length; j++) {
		stkOpt += "<option value='" + g_var.stkGroup[j].split(" ")[0] + "' >" +              
							g_var.stkGroup[j].split(" ")[1] + "</option>";
	}
	//alert("stkOpt: "+stkOpt);
	
	var stkLst = "";
	stkLst += "<select style='width:49%' id='STK_LIST' onchange='_gel(" + '"STK_LIST"' + ").value=this.options[this.selectedIndex].value;'><option value =''>clean</option>" + stkOpt + "</select>";
	//alert("stkLst: "+stkLst);
	
	_gel("stklist_div").innerHTML = stkLst;
	_gel("STK_LIST").onchange = function(){ ShowStockInfo1(g_var); };
	
	//_IG_AdjustIFrameHeight();
}

function ShowStockInfo1(g_var) {
	//alert(_gel("STK_LIST").value);
	var stkId = _gel("STK_LIST").value;
	var stk;
	if (stkId == "All") {
		var stkDb = new ObjStkDb();
		stkDb.Create();
		dbgMsg(stkDb.objStk.length);
		//stk = stkDb.stkId;
	} else if (stkId == "Div") {
		stk = g_var.stkDiv;
	} else if (stkId == "IcDesign") {
		stk = g_var.stkIcDesign;	
	} else if (stkId == "Steel") {
		stk = g_var.stkSteel;
	} else if (stkId == "Wafer") {
		stk = g_var.stkWafer;
	} else if (stkId == "OnlineGame") {
		stk = g_var.stkOnlineGame;		
	}	else if (stkId == "Dram") {
		stk = g_var.stkDram;
	} else if (stkId == "Mobile") {
		stk = g_var.stkMobile;
	}	else if (stkId == "Telecom") {
		stk = g_var.stkTelecom;
	} else if (stkId == "Tourism") {
		stk = g_var.stkTourism;
	}	else {
		dbgMsg("");
		g_var.ResetMinMsg();
		return;
	}
	
	g_var.ResetMinMsg();
	//alert(stk.length);
	for (var i=0; i < stk.length; i++) {
		var ret = displayStock(g_var, stk[i].split(" ")[0]);
		nap(500);
		_IG_AdjustIFrameHeight();
	}
		
	dbgMsg("done");
	_IG_AdjustIFrameHeight();
}

function extractString(content, pattern1, pattern2, offset1, offset2) {
  var headPos = content.search(pattern1)+pattern1.length+offset1; 
  var tailPos = content.substring(headPos).search(pattern2);
  //dprint("headPos="+headPos+" tailPos="+tailPos);
  return content.substr(headPos, tailPos);
}

function nap (m) {var then = new Date(new Date().getTime() + m); while (new Date() < then) {setTimeout('return;', 500);}}

function tradeInfo(stockId) {
	//alert("stkId: "+stockId);

	var res = "";
	_IG_FetchContent("http://www.cnyes.com/twstock/div/home_quote_js.asp?code="+stockId, 
		//_IG_Callback(parse, g_var), { refreshInterval: 0 });
		function(response) { res = parse(response); });

	function parse(response, g_var) {
		var result = "";
		for (var i=1; i < response.split("\'+\'").length-1; i++) {
			result += response.split("\'+\'")[i];
		}
		//if (result.length == 0) alert(response);	
		return result;
	}
	//nap(1000);	
	return res;
}

function displayStock(g_var, stockId) {
		
  // XML breakfast menu data
  var url = "http://megatime.cnyes.com/twstock/"+stockId+".htm";
  //var prefs = new _IG_Prefs(__MODULE_ID__);
  //alert(url);
  
  var trdInfo = tradeInfo(stockId);
  //_IG_FetchXmlContent(url, function (response) {
  _IG_FetchContent(url, function(response) {
  	var html_ = "";

	  if (response == null || response.length == 0) {
	    //_gel("content_div").innerHTML = "<i>Invalid data.</i>";
	    dbgMsg("response null: "+stockId);
	    return false;
	  }	
		//alert(response);
	
	  // Start building HTML string that will be displayed in <div>.
	  // Set the style for the <div>.
	  /*g_var.html*/html_ += "<div style='padding: 5px;background-color: #ccf;font-family:Arial, Helvetica;" +
	          "text-align:left;font-size:90%'>";     
	        	
	  // Set style for title.
	  /*g_var.html*/html_ += "<div style='text-align:center; font-size: 120%; color: blue; " +
	          "font-weight: 700;'>";     
	
	  // Display menu title. Use getElementsByTagName() to retrieve the <menu> element.
	  // Since there is only one menu element in the file,
	  // you can get to it by accessing the item at index "0". 
	  // You can then use getAttribute to get the text associated with the
	  // menu "title" attribute.
	  var title = extractString(response, "<title>", "-", 0, 0);
	  //alert("title="+title);
	
	  // Append the title to the HTML string.
	  /*g_var.html*/html_ += title + "</div><br>";
	
		//alert(response);
	  var info = extractString(response, "<ul>", "<ul>", 97, 0);
	  //alert("info="+info);
	  
	  var ObjAly = new ObjAnalysis();
	  ObjAly.parse(info);
	  if (ObjAly.shortStar < 2 || ObjAly.medStar < 2 || ObjAly.longStar < 2
	  		|| ObjAly.shortTrend < 0 || ObjAly.medTrend < 0
	  		|| ObjAly.opt < 0
	  		//|| ObjAly.longStar < 2
	  		|| ObjAly.per200 < 50.0) {
	  	 //alert(ObjAly.shortStar+", "+ObjAly.medStar+", "+ObjAly.longStar+", "+ObjAly.per200);
	  	g_var.html = "";
	  	return false;
	 	}

	  /*g_var.html*/html_ += info + "<br>";
	  //info = extractString(response, "light04-1.gif", "<td>&#x9032;&#x51FA;&#x7B56;&#x7565;</td>", 9);
	  
	  /*g_var.html*/html_ += trdInfo;	//tradeInfo(stockId);
	
	  /*g_var.html*/html_ += "</div>";
	
		//_gel('stkinfo1_div').innerHTML = g_var.html;
	 	g_var.minMsg.createDismissibleMessage(/*g_var.html*/html_);
	 	g_var.html = "";
	
		_IG_AdjustIFrameHeight();
	});	  
    
  return true;
}
